pandas csv sum column

39

import pandas as pd
data = pd.read_csv('pandas.csv')
df = pd.DataFrame(data)
id_sum = 0
data_sum = 0
for i in range(len(df)):
   if(i==len(df)-2 or i==len(df)-1):
      id_sum = id_sum + df.iloc[i][0]
      data_sum = data_sum + df.iloc[i][1]
print("Id",id_sum)
print("Data",data_sum)

Comments

Submit
0 Comments